﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Rated.Website.Exceptions;
using Rated.DAL.Db;

namespace Rated.Website.Classes
{
    public class Breadcrumb
    {
        public string Text {get;private set;}
        public int Value {get;private set;}
        public Breadcrumb()
        {
            throw new EIncorrectConstructor();
        }

        public Breadcrumb(string text, int value)
        {
            Text = text;
            Value = value;
        }
    }
    
    public class BreadcrumbTrail
    {
        public List<Breadcrumb> Trail { get; private set; }

        public BreadcrumbTrail()
        {
            throw new EIncorrectConstructor();
        }

        public BreadcrumbTrail(RatedItem item)
        {
            var db = new RatedEntities();
            int? continentid = item.ContinentID;
            int? countryId = item.CountryID;
            int? localityId = item.LocalityID;
            int? stateId = item.StateID;
            int? cityId = item.CityID;
            Trail = new List<Breadcrumb>();
            if (item.ContinentID == null)
                AddBreadcrumb("Worldwide", 0);
            else
            {
                AddBreadcrumb(item.Continent.Name, item.ContinentID.Value);
                if (item.CountryID != null)
                {
                    AddBreadcrumb(item.Country.Name, item.CountryID.Value);
                    if (item.LocalityID != null)
                    {
                        AddBreadcrumb(item.Locality.Name, item.LocalityID.Value);
                        if (item.StateID != null)
                        {
                            AddBreadcrumb(item.State.Name, item.StateID.Value);
                            if (item.CityID != null)
                                AddBreadcrumb(item.City.Name, item.CityID.Value);
                        }
                    }
                }
            }
        }

        private void AddBreadcrumb(string text, int value)
        {
            var bc = new Breadcrumb(text,value);
            Trail.Add(bc);

        }


    }
}